/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace DaveSexton.DocProject.Sandcastle.ContentManagement
{
	internal sealed class XmlContentDialogSettings : DialogSettings<XmlContentDialog>
	{
		#region Public Properties
		public static readonly Guid DialogGuid = new Guid("853993B4-7696-40f3-907C-C83872C4676E");

		public int AttributesGridHeight
		{
			get
			{
				return Read("attributesGridHeight", 0);
			}
			set
			{
				Write("attributesGridHeight", value);
			}
		}

		public int DocumentListHeight
		{
			get
			{
				return Read("documentListHeight", 0);
			}
			set
			{
				Write("documentListHeight", value);
			}
		}

		public int ContentListWidth
		{
			get
			{
				return Read("contentListWidth", 0);
			}
			set
			{
				Write("contentListWidth", value);
			}
		}
		#endregion

		#region Private / Protected
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="XmlContentDialogSettings" /> class.
		/// </summary>
		public XmlContentDialogSettings(XmlContentDialog dialog)
			: base(dialog, DialogGuid)
		{
			dialog.ContentDocumentListHeightChanged += dialog_ContentDocumentListHeightChanged;
			dialog.ContentListWidthChanged += dialog_ContentListWidthChanged;
			dialog.ContentAttributesGridHeightChanged += dialog_ContentAttributesGridHeightChanged;
		}
		#endregion

		#region Methods
		protected override void LoadInternal()
		{
			int documentListHeight = this.DocumentListHeight;

			if (documentListHeight > 0)
			{
				try
				{
					Dialog.ContentDocumentListHeight = documentListHeight;
				}
				catch (InvalidOperationException) { this.DocumentListHeight = Dialog.ContentDocumentListHeight; }
				catch (ArgumentException) { this.DocumentListHeight = Dialog.ContentDocumentListHeight; }
			}

			int contentListWidth = this.ContentListWidth;

			if (contentListWidth > 0)
			{
				try
				{
					Dialog.ContentListWidth = contentListWidth;
				}
				catch (InvalidOperationException) { this.ContentListWidth = Dialog.ContentListWidth; }
				catch (ArgumentException) { this.ContentListWidth = Dialog.ContentListWidth; }
			}

			int attributesGridHeight = this.AttributesGridHeight;

			if (attributesGridHeight > 0)
			{
				try
				{
					Dialog.ContentAttributesGridHeight = attributesGridHeight;
				}
				catch (InvalidOperationException) { this.AttributesGridHeight = Dialog.ContentAttributesGridHeight; }
				catch (ArgumentException) { this.AttributesGridHeight = Dialog.ContentAttributesGridHeight; }
			}
		}
		#endregion

		#region Event Handlers
		private void dialog_ContentDocumentListHeightChanged(object sender, EventArgs e)
		{
			if (!Loading)
				this.DocumentListHeight = Dialog.ContentDocumentListHeight;
		}

		private void dialog_ContentListWidthChanged(object sender, EventArgs e)
		{
			if (!Loading)
				this.ContentListWidth = Dialog.ContentListWidth;
		}

		private void dialog_ContentAttributesGridHeightChanged(object sender, EventArgs e)
		{
			if (!Loading)
				this.AttributesGridHeight = Dialog.ContentAttributesGridHeight;
		}
		#endregion
	}
}
